OPC Studio User's Guide and Reference
Browsing for OPC Classic Properties
View with Navigation Tools
Concepts > OPC Data Client Concepts > OPC Data Client Development Models > Imperative Programming Model > Imperative Programming Model for OPC Data (Classic and UA) > Browsing for Information (OPC Data) > Browsing for OPC Classic Properties
In This Topic

Introduction

Each OPC item has typically associated a set of OPC properties with it. OPC properties contain additional information related to the item. The OPC specifications define a set of common properties; however, each OPC server is free to implement some more, vendor-specific properties as well.

If you want to retrieve a list of all properties available on a given OPC item, call the BrowseProperties method, passing it the ItemID you are interested in. You will receive back a DAPropertyElementCollection object. Each DAPropertyElement contains information about one OPC property, such as its (numeric) PropertyId, data type, or a readable description. The PropertyId can be later used as an argument in calling methods such as GetPropertyValue.

You can use DAPropertyId.GetName and GetPropertyType methods to obtain the string identifier of the property, or its type. With OPC XML, properties are identified by a XML qualified name, and you will find it in the DAPropertyElement.QualifiedName property.

Constants for specific (well-known) OPC properties are contained in the DAPropertyIds enumeration.

Examples

Browse for properties

.NET

// This example shows how to enumerate all properties of an OPC item. For each property, it displays its Id and description.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.AddressSpace;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    class BrowseProperties
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();
            DAPropertyElementCollection propertyElements;
            try
            {
                propertyElements = client.BrowseProperties("OPCLabs.KitServer.2", "Simulation.Random");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (DAPropertyElement propertyElement in propertyElements)
                Console.WriteLine($"PropertyElements(\"{propertyElement.PropertyId.NumericalValue}\").Description: {propertyElement.Description}");
        }


        // Example output:
        //
        //PropertyElements("15008").Description: Visible
        //PropertyElements("5").Description: Item Access Rights
        //PropertyElements("2").Description: Item Value
        //PropertyElements("7").Description: Item EU Type
        //PropertyElements("15001").Description: Item Name
        //PropertyElements("4").Description: Item Timestamp
        //PropertyElements("1").Description: Item Canonical Data Type
        //PropertyElements("103").Description: Low EU
        //PropertyElements("15009").Description: Addable
        //PropertyElements("6").Description: Server Scan Rate
        //PropertyElements("15000").Description: Item ID
        //PropertyElements("3").Description: Item Quality
    }
}

COM

// This example shows how to enumerate all properties of an OPC item. For each property, it displays its Id and description.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure BrowseProperties.Main;
var
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  Count: Cardinal;
  Element: OleVariant;
  ServerDescriptor: _ServerDescriptor;
  NodeDescriptor: _DANodeDescriptor;
  PropertyElement: _DAPropertyElement;
  PropertyElementEnumerator: IEnumVariant;
  PropertyElements: _DAPropertyElementCollection;
begin
  ServerDescriptor := CoServerDescriptor.Create;
  ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';

  NodeDescriptor := CoDANodeDescriptor.Create;
  NodeDescriptor.ItemId := 'Simulation.Random';

  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  try
    PropertyElements := Client.BrowseProperties(
      ServerDescriptor,
      NodeDescriptor);
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  PropertyElementEnumerator := PropertyElements.GetEnumerator;
  while (PropertyElementEnumerator.Next(1, Element, Count) = S_OK) do
  begin
    PropertyElement := IUnknown(Element) as _DAPropertyElement;
    WriteLn('PropertyElements("', PropertyElement.PropertyId.NumericalValue, '").Description: ', PropertyElement.Description);
  end;
end;

Python

# This example shows how to enumerate all properties of an OPC item. For each property, it displays its Id and
# description.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyDAClient()

# Perform the operation.
try:
    propertyElements = IEasyDAClientExtension.BrowseProperties(client, '', 'OPCLabs.KitServer.2', 'Simulation.Random')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results.
for propertyElement in propertyElements:
    print('PropertyElements[', propertyElement.PropertyId.NumericalValue, '].Description: ', propertyElement.Description,
          sep='')

 

Browse for properties in OPC XML-DA 

.NET

// This example shows how to enumerate all properties of an OPC XML-DA item. For each property, it displays its Id and description.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.AddressSpace;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess.Xml
{
    class BrowseProperties
    {
        public static void Main1Xml()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();
            DAPropertyElementCollection propertyElements;
            try
            {
                propertyElements = client.BrowseProperties("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (DAPropertyElement propertyElement in propertyElements)
                Console.WriteLine($"PropertyElements(\"{propertyElement.PropertyId.NumericalValue}\").Description: {propertyElement.Description}");
        }


        // Example output:
        //
        //PropertyElements("1").Description: Item Canonical DataType
        //PropertyElements("2").Description: Item Value
        //PropertyElements("3").Description: Item Quality
        //PropertyElements("4").Description: Item Timestamp
        //PropertyElements("5").Description: Item Access Rights
        //PropertyElements("6").Description: Server Scan Rate
        //PropertyElements("7").Description: Item EU Type
        //PropertyElements("8").Description: Item EU Info
        //PropertyElements("102").Description: High EU
        //PropertyElements("103").Description: Low EU
    }
}

Python

# This example shows how to enumerate all properties of an OPC XML-DA item. For each property, it displays its Id and description.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *

# Instantiate the client object.
client = EasyDAClient()

try:
    propertyElements = client.BrowseProperties(ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DANodeDescriptor('Dynamic/Analog Types/Int'))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

for propertyElement in propertyElements:
    print('PropertyElements("', propertyElement.PropertyId.NumericalValue, '").Description: ', propertyElement.Description, sep='')

# Example output:
#
#PropertyElements("1").Description: Item Canonical DataType
#PropertyElements("2").Description: Item Value
#PropertyElements("3").Description: Item Quality
#PropertyElements("4").Description: Item Timestamp
#PropertyElements("5").Description: Item Access Rights
#PropertyElements("6").Description: Server Scan Rate
#PropertyElements("7").Description: Item EU Type
#PropertyElements("8").Description: Item EU Info
#PropertyElements("102").Description: High EU
#PropertyElements("103").Description: Low EU

 

OPC Data Client supports OPC XML-DA also on Linux and macOS.

 

See Also

Examples - Client OPC Data Access

Examples - Client OPC XML-DA